<template>
  <div class="swiper-box">
    <div class="swiper mySwiper">
      <div class="swiper-wrapper">
        <div class="swiper-slide"
          v-for="(item,index) in arr"
          :key="index"
          :class="[activeIndex==index?'active':'','item']">
          {{item}}
        </div>
        <!-- <div class="swiper-slide active">123</div>
        <div class="swiper-slide">123</div>
        <div class="swiper-slide">123</div>
        <div class="swiper-slide">123</div>
        <div class="swiper-slide">123</div>
        <div class="swiper-slide">123</div>
        <div class="swiper-slide">123</div> -->
      </div>
    </div>
  </div>
</template>

<script>
  import Swiper from 'swiper'
  import 'swiper/css/swiper.css'
  export default {
    data() {
      return {
        arr: [],
        activeIndex: 0
      }
    },
    created() {
      setTimeout(() => {
        console.log(this.arr.push(...['less', 'css', 'js', 'less', 'css', 'js', 'less', 'css', 'js', 'less', 'css', 'js']))
        // this.arr.psuh()
      }, 2000)
    },
    mounted() {
      new Swiper('.mySwiper', {
        slidesPerView: 3,
        spaceBetween: 30,
        freeMode: false
      })
    },
    updated() {
      new Swiper('.mySwiper', {
        slidesPerView: 3,
        spaceBetween: 30,
        freeMode: false
      })
    }
  }
</script>

<style lang="less" scoped>
.swiper-box {
  width: 100vw;
  height: 30px;
  overflow: hidden;
}
.swiper {
  width: 100%;
  height: 30px;
}
.swiper-wrapper {
  display: flex;
}
.swiper-slide {
  width: 60px;
  height: 30px;
  text-align: center;
  font-size: 18px;
  // margin-top: 10px;
  margin-right: 10px;
  background: #ccc;
  /* Center slide text vertically */
  display: -webkit-box;
  display: -ms-flexbox;
  display: -webkit-flex;
  display: flex;
  -webkit-box-pack: center;
  -ms-flex-pack: center;
  -webkit-justify-content: center;
  justify-content: center;
  -webkit-box-align: center;
  -ms-flex-align: center;
  -webkit-align-items: center;
  align-items: center;
}

.swiper-slide {
  .item {
    width: 30px;
    height: 15px;
  }
  &.active {
    color: red;
  }
}
</style>